package com.cdpm.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cdpm.common.utils.CollectionUtil;
import com.cdpm.system.domain.StrategyInstance;
import com.cdpm.system.mapper.StrategyInstanceMapper;
import com.cdpm.system.service.IStrategyInstanceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: longjy
 * @create: 2024-08-29 16:07
 **/
@Service
public class StrategyInstanceServiceImpl implements IStrategyInstanceService {

    @Resource
    StrategyInstanceMapper strategyInstanceMapper;

    @Override
    public List<StrategyInstance> findList(StrategyInstance strategyInstance) {
        List<StrategyInstance> list = strategyInstanceMapper.findList(strategyInstance);
        return list;
    }

    @Override
    public int insert(StrategyInstance strategyInstance) {
        return strategyInstanceMapper.insert(strategyInstance);
    }

    @Override
    public int update(StrategyInstance strategyInstance) {
        return strategyInstanceMapper.updateById(strategyInstance);
    }

    @Override
    public StrategyInstance findById(Long strategyInstanceId) {
        StrategyInstance strategyInstance = new StrategyInstance();
        QueryWrapper<StrategyInstance> queryWrapper = new QueryWrapper();
        queryWrapper.eq("strategy_instance_id",strategyInstanceId+"");
        List<StrategyInstance> strategyInstances = strategyInstanceMapper.selectList(queryWrapper);
        if(CollectionUtil.isNotEmpty(strategyInstances)){
            strategyInstance = strategyInstances.get(0);
        }
        return strategyInstance;
    }
}
